package netty.DelimiterBasedFrameDecoder;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author Kagome
 * @title: SocketServerHandler
 * @projectName boot2.X-netty
 * @description: TODO
 * @date 2019/6/4 13:06
 */
public class SocketServerHandler extends ChannelInboundHandlerAdapter {
    private int counter;

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        //打印客户端发送的数据
        String body = (String)msg;
        System.out.println("This is " + ++counter + " times receive from client:"+body+"");
        body = body + "$_";
        ByteBuf byteBuf = Unpooled.copiedBuffer(body.getBytes());
        ctx.writeAndFlush(byteBuf);
    }
}

